package com.hdu.other.dp.pakegeGroup;

import java.util.List;

public class lc2218 {
    class Solution {
        public int maxValueOfCoins(List<List<Integer>> piles, int k) {

            int groupSize = piles.size();
            int[][] dp = new int[groupSize + 1][k + 1];

            for (int i = 1; i <= groupSize; i++) {
                List<Integer> curGroup = piles.get(i - 1);
                for (int j = 0; j <= k; j++) {
                    dp[i][j] = dp[i - 1][j];
                    int curCost = 0;
                    int curValue = 0;
                    for (int item : curGroup) {
                        curCost++;
                        curValue += item;
                        if (curCost <= j) {
                            dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - curCost] + curValue);
                        }
                    }
                }
            }
            return dp[groupSize][k];
        }
    }
}
